#!/usr/bin/env bash
if [[ "`id -u`" != "0" ]]; then sudo -sE "${0}" "${1}" || exit 1; exit; fi;
f_fail(){ echo -e "\033[31m[FAIL]\033[0m ${1}" >&2; exit 1; }

if [[ "$1" = "-t" ]]; then nginx -t;
elif [[ "$1" = "start" ]]; then systemctl start nginx;
elif [[ "$1" = "stop" ]]; then systemctl stop nginx;
elif [[ -z "${1}" ]] || [[ "$1" = "restart" ]]; then systemctl restart nginx;
elif [[ "$1" = "status" ]]; then systemctl status nginx;
else f_fail 'usage: ngx.sh [-t|start|stop|restart|status]'; fi;

echo >/dev/null;
